package com.example.resturant.controller;

import com.example.resturant.repository.NewsRepository;
import lombok.var;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@RequestMapping("/news")
@Controller
public class NewsController {

    @Resource
    private NewsRepository newsRepository;

    @GetMapping
    public String news(Model model, @PageableDefault Pageable page) {
        var res = newsRepository.findByDeleted(false, page);
        model.addAttribute("newsList", res);
        return "news";
    }
}
